Skip to content

feat: add per-call max_fee_bps slippage protection to deduct - #519

Merged
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
Okorie2000-code:feat/498-max-fee-bps-slippage-guard
Jun 27, 2026
Merged

feat: add per-call max_fee_bps slippage protection to deduct#519
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
Okorie2000-code:feat/498-max-fee-bps-slippage-guard

Conversation

@Okorie2000-code

Copy link
Copy Markdown
Contributor

Summary

Implements issue #498. Adds a max_fee_bps: u16 parameter to deduct that reverts with the new typed VaultError::Slippage (code 35) when the deducted amount expressed in basis points of the current balance exceeds the caller's limit.

calculated_fee_bps = (amount * 10_000) / balance
if calculated_fee_bps > max_fee_bps → VaultError::Slippage

Pass u16::MAX (65535) to disable the guard — backward-compatible default for all existing integrations.

Security rationale

The slippage guard is a pre-mutation check. It fires after input validation and idempotency checks but strictly before any state write or external token transfer. A failed check leaves the vault in exactly the state it was before the call — no partial effects, no balance change. This protects callers against race conditions or unexpected balance drift that could cause a single call to drain a disproportionately large fraction of the vault.

Changes

  • lib.rsSlippage = 35 added to VaultError; max_fee_bps: u16 added to deduct; slippage check inserted before state mutation.
  • test.rs — 8 new targeted tests (below/equal/above limit, u16::MAX, boundary 0 and 1 bps, pre-mutation assertion, regression).
  • All existing deduct / try_deduct call sites updated to pass &u16::MAX.
  • docs/interfaces/vault.jsonmax_fee_bps param and Slippage (35) error documented.

Closes

Closes #498

@drips-wave

drips-wave Bot commented Jun 27, 2026

Copy link
Copy Markdown

@Okorie2000-code Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@greatest0fallt1me

Copy link
Copy Markdown
Contributor

Merged via direct push to main (admin)

@greatest0fallt1me
greatest0fallt1me merged commit 09ac854 into CalloraOrg:main Jun 27, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add per-call max_fee_bps slippage guard to deduct

2 participants